<template>
  <div class="interviewList">
    <!-- 标题 -->
    <van-nav-bar
      :fixed="true"
      class="title"
      title="面试技巧列表"
      right-text="搜索"
      left-arrow
      @click-left="$router.back()"
      @click-right="$router.push('/interviewSearch')"
    />
    <!-- 内容 -->
    <van-list
      class="main"
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
    >
      <!-- v-for="item in list" :key="item" :title="item" -->
      <van-cell v-for="(item, index) in dataList" :key="index">
        <!-- item -->
        <div class="item" @click="$router.push('/interviewDetail/' + item.id)">
          <div class="content">
            <p>{{ item.title }}</p>
            <div class="info">
              <div class="time">
                <span>{{ item.created_at | dateStyleOne }}</span>
              </div>
              <div class="flex"></div>
              <div class="right">
                <van-icon name="eye-o" />
                <span>{{ item.read }}</span>
                <van-icon
                  name="good-job-o"
                  :class="{ red: starArtList.includes(item.id) }"
                />
                <span>{{ item.star }}</span>
              </div>
            </div>
          </div>
          <img :src="baseUrl + item.cover" alt="" />
        </div>
      </van-cell>
    </van-list>
  </div>
</template>

<script>
// 导入api
import { apiInterviewingList } from '@/api/find.js'
export default {
  data () {
    return {
      baseUrl: process.env.VUE_APP_URL,
      dataList: [], // 数据
      // 页数
      start: 0,
      // 刷新控制
      loading: false,
      finished: false,
      starArtList: [] // 文章点赞列表
    }
  },
  methods: {
    async onLoad () {
      // 面经列表
      const res = await apiInterviewingList({
        start: this.start,
        limit: 5,
        q: ''
      })
      this.dataList = [...this.dataList, ...res.data.list]
      // 终点判断
      if (res.data.list.length < 5) {
        this.finished = true
      }
      // 页码+1
      this.start += 5
      // 停止加载
      this.loading = false
    }
  },
  mounted () {
    // 获取用户点赞列表
    if (this.$store.state.userInfo.starArticles) {
      this.starArtList = this.$store.state.userInfo.starArticles
    }
  }
}
</script>

<style lang="less" scoped>
.interviewList {
  opacity: 1;
  margin-top: 46px;
  .red {
    color: red !important;
  }
  /* 标题 */
  .title {
    background-color: #ca0131;
    /deep/.van-nav-bar__title {
      color: #fff;
    }
    /deep/ .van-icon {
      color: #fff;
    }
    /deep/ .van-nav-bar__text {
      color: #fff;
    }
  }
  /* 数据 */
  .info {
    display: flex;
    height: 20px;
    .flex {
      flex: 1;
    }
    .van-icon {
      line-height: 20px;
      font-size: 14px;
    }
    span {
      vertical-align: middle;
      line-height: 20px;
      font-size: 12px;
      padding: 0 7px;
    }
  }
  .item {
    display: flex;
    align-items: center;
    height: 125px;
    padding-top: 10px;
    padding-bottom: 25px;
    .content {
      height: 100%;
      width: 65%;
      padding-right: 10px;
      p {
        margin: 0;
        height: 70px;
        font-size: 16px;
      }
    }
    img {
      width: 35%;
      height: 90px;
    }
  }
}
</style>
